package visualizer.google;

import java.net.URL;

import org.json.JSONObject;

public class GoogleService {
	private JsonRequest request;
	private GoogleRequestUrlBuilder urlBuilder;
	
	public GoogleService(JsonRequest request, GoogleRequestUrlBuilder urlBuilder)
	{
		this.request = request;
		this.urlBuilder = urlBuilder;
	}
	
	public GoogleResponse execute(String query)
	{
		URL u = getRequestUrl(query);
		if (u != null) {
			JSONObject data = request.execute(u);
			if (data != null) {
				return new GoogleResponse(data);
			}
		}
		return new GoogleResponse(new JSONObject());
	}
	
	protected URL getRequestUrl(String query)
	{
		return urlBuilder.setQuery(query).build();
	}
}
